package com.ease.framework.gef4p.editparts {
   import com.ease.common.models.IModel;
   import com.ease.framework.gef.EditPart;
   import com.ease.framework.gef.IEditor;
   import com.ease.framework.gef4p.commands.RemoveAnnotationCommand;
   import com.ease.framework.gef4p.figures.impl.AnnotationFigure;
   import com.ease.framework.gef4p.model.Annotation;
   import com.ease.framework.workbench.Workbench;
   import com.ease.framework.workbench.spi.ICommand;

   import flash.events.ContextMenuEvent;
   import flash.ui.ContextMenuItem;

   public class AnnotationEditPart extends EditPart {
      public function AnnotationEditPart(obj:IModel) {
         super(obj);
      }

      override public function doRefreashFigure():void {
         figure.x = Annotation(model).x;
         figure.y = Annotation(model).y;
         figure.width = Annotation(model).width;
         figure.height = Annotation(model).height;
         AnnotationFigure(figure).getLabelFigure().text = Annotation(model).content;
      }

      override public function createCustomContextMenuItems():void {
         var menuItem_delete:ContextMenuItem = new ContextMenuItem("删除注释");
         menuItem_delete.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, handleRemove);
         this.pushCustomContextMenuItem(menuItem_delete);
      }

      private function handleRemove(param1:ContextMenuEvent):void {
         var command:ICommand = new RemoveAnnotationCommand(model as Annotation);
         IEditor(Workbench.instance.currentEditor).getEditDomain().getCommandStack().push(command);
      }
   }
}